package com.freemyleft.left.left_app.mian.index.my.Mystudent;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.freemyleft.left.zapp.ui.recycler.DataConverter;
import com.freemyleft.left.zapp.ui.recycler.MultipleFields;
import com.freemyleft.left.zapp.ui.recycler.MultipleItemEntity;


import java.util.ArrayList;

import static com.freemyleft.left.left_app.mian.index.my.Mystudent.MyStudentAdapter.STUDENT_TYPE;

public class StudentCovert extends DataConverter {
    ArrayList<MultipleItemEntity> entities = new ArrayList<>();

    @Override
    public ArrayList<MultipleItemEntity> convert() {
        JSONObject object = JSONObject.parseObject(getJsonData());
        JSONArray result = object.getJSONArray("result");
        int size = result.size();
        for (int i = 0; i < size; i++) {
            JSONObject object1 = result.getJSONObject(i);
            String id = object1.getString("id");
            String name = object1.getString("name");
            String sex = object1.getString("sex");
            String head = object1.getString("head");
            String studentid = object1.getString("studentid");
            String credit = object1.getString("credit");
            String phoen = object1.getString("credit");
            MultipleItemEntity entity = MultipleItemEntity.builder()
                    .setField(MultipleFields.ITEM_TYPE ,STUDENT_TYPE)
                    .setField(MyStudentAdapter.StudendFlies.NAME, name)
                    .setField(MyStudentAdapter.StudendFlies.ID, id)
                    .setField(MyStudentAdapter.StudendFlies.XING_YONG, credit)
                    .setField(MyStudentAdapter.StudendFlies.HEAD, head)
                    .build();
            entities.add(entity);
        }
        return entities;
    }
}
